//
//  CPBaseTableViewController.swift
//  weibo
//
//  Created by zcp on 16/5/10.
//  Copyright © 2016年 zcp. All rights reserved.
//

import UIKit

class CPBaseTableViewController: UITableViewController {

    //是否已经登录
    var userLogin: Bool = CPUserAccountViewModel.sharedAccountViewModel.isLogin()
    override func loadView() {
        super.loadView()
    }
    override func viewDidLoad() {
        

        
        if userLogin {
        
            super.viewDidLoad()
            
            
        }
        else
        {
            //设置导航栏的两边的按钮
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewClickloginBtn")
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewClickRegisterBtn")
            
            //把自定义访客view赋值给控制器的view
            view = visitorView
            //指定代理
            visitorView.delegate = self
//            self.view.backgroundColor = UIColor.whiteColor()
            //判断是那个控制器,修改为相应的访客view
            if self is CPHomeViewController{
            
                visitorView.addAnimation()
            }
            else if self is CPDiscoveryViewController{
            
                visitorView.visitorView("登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过", imageName: "visitordiscover_image_message")
            }
            else if self is CPMessageViewController{
            
                visitorView.visitorView("登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", imageName: "visitordiscover_image_message")
            }
            else if self is CPProfileTableViewController{
            
                visitorView.visitorView("登录后，你的微博、相册、个人资料会显示在这里，展示给别人", imageName: "visitordiscover_image_profile")
            }
        }
        
    }

    //懒加载访客view
    lazy var visitorView: CPVisitorView = CPVisitorView()
}
//MARK -- 在进入登录状态下导航栏按钮点击操作
func didLeftClilk(){


    print("didLeftClilk")
}
func didRightClick(){
    
    
    print("didRightClick")
}
//MARK 扩展
extension CPBaseTableViewController: CPVisitorViewDelegate {
    func visitorViewClickRegisterBtn() {
        print("111")
    }
    func visitorViewClickloginBtn() {
        self.presentViewController(UINavigationController(rootViewController: CPOauthViewController()), animated: true, completion: nil)
    }
    
    
}
